package recycle.impl;

import org.springframework.stereotype.Service;
import recycle.dao.OrderdetailMapper;
import recycle.pojo.Orderdetail;
import recycle.service.OrderdetailService;
import recycle.utils.Page;
import recycle.vo.OrderdetailParam;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
* 描述：订单详情表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class OrderdetailServiceImpl implements OrderdetailService{
	@Resource
	private OrderdetailMapper orderdetailMapper;
 	
 	/**
    * 描述：根据Id获取Orderdetail对象
    * @param id
    */
    public Orderdetail findById(Serializable orderDetailId){
    	return orderdetailMapper.findById(orderDetailId);
    }
    /**
    * 描述：获取所有的Orderdetail对象
    */
    public List<Orderdetail> findAll(){
    	return orderdetailMapper.findAll();
    }

	/**
    * 描述：新增保存Orderdetail对象
    */
    public int save(Orderdetail orderdetail){
    	return  orderdetailMapper.save(orderdetail);
    }

	/**
    * 描述：根据Id删除Orderdetail对象
    * @param id
    */
    public int delete(Serializable orderDetailId){
    	return  orderdetailMapper.delete(orderDetailId);
    }
	
	/**
    * 描述：更新Orderdetail对象
    */
    public int update(Orderdetail orderdetail){
    	return  orderdetailMapper.update(orderdetail);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Orderdetail> query(OrderdetailParam param){
    	return  orderdetailMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(OrderdetailParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = orderdetailMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = orderdetailMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

}
